package com.hisense.hiioc.formtable.util;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.sql.Timestamp;


/**
 * MD5加密类
 *
 */
public class MD5 {
	/**
	 * MD5加密
	 * @param
	 *
	 */
	private static final char HEX_DIGITS[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
        'a', 'b', 'c', 'd', 'e', 'f' };

	public static String toHexString(byte[] b) {  //String to  byte
        StringBuilder sb = new StringBuilder(b.length * 2);
        for (int i = 0; i < b.length; i++) {
            sb.append(HEX_DIGITS[(b[i] & 0xf0) >>> 4]);
            sb.append(HEX_DIGITS[b[i] & 0x0f]);
        }
        return sb.toString();
	  }

	  //MD5加密
    public String encrypt(String s) {
    	 try {
             // Create MD5 Hash
             MessageDigest digest = MessageDigest.getInstance("MD5");
             digest.update(s.getBytes());
             byte messageDigest[] = digest.digest();
             return toHexString(messageDigest);
         } catch (NoSuchAlgorithmException e) {
             e.printStackTrace();
         } catch (Exception e) {
        	 e.printStackTrace();
         }
       return "";
   }

	public static void main(String args[]){

		MD5 md5 = new MD5();
		String str="123456";
        System.out.println(md5.encrypt(str));

        System.out.println(new Timestamp(1512040463l*1000));
	}
}
